package com.xy.tianyu.module.novel.adapter

import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.xy.tianyu.module.novel.bean.X
import com.xy.tianyu.utils.GlideUtils
import com.youth.banner.adapter.BannerAdapter

/**
 * @time 2020/11/26 15:09
 * @class 描述:
 */
class CompetitiveRecommendBannerAdapter(list: MutableList<X>?) :
    BannerAdapter<X, CompetitiveRecommendBannerAdapter.BannerViewHolder>(list) {

    class BannerViewHolder(var imageView: ImageView) :
        RecyclerView.ViewHolder(imageView)

    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): BannerViewHolder {
        val imageView = ImageView(parent!!.context)
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        return BannerViewHolder(imageView)
    }

    override fun onBindView(holder: BannerViewHolder?, data: X?, position: Int, size: Int) {
        val imageView = holder!!.imageView
        Glide.with(imageView.context).load(data?.adImgUrl).apply(GlideUtils.getRequestOptions()).into(imageView)
    }

}